home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / OOP.SWG / 0030_Object Checking.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  1KB  |  32 lines

  1. {
  2. > But it's not bad if they DON'T have them, is it? Defining what is good or
  3. > bad from reading the manual is the single most difficult problem I have
  4. > with them for anything (not just TP). I wouldn't suppose
  5. > it would be if you can do it.
  6.  
  7. I'm not sure what you mean by good or bad.  If you want to use virtual methods,
  8. you need a VMT.  Not having one would be very bad.  If you don't want to use
  9. virtual methods, then you probably don't need a VMT.  The only reason you might
  10. want one is for debugging:  you can check whether an object has been
  11. initialized by checking whether its VMT is valid.  Here's the check I use:
  12. }
  13.  
  14. Function ObjCheck(o:PObject;msg:string):boolean;
  15. type
  16.   VMT = record
  17.           size, negsize : integer;
  18.         end; var
  19.   PVmt : ^VMT;
  20. begin
  21.   PVmt := Ptr(DSeg, word(Pointer(o)^));
  22.   with PVmt^ do
  23.     if (size = 0) or (size + negsize <> 0) then
  24.     begin
  25.       write(msg,':  Not initialized');
  26.       ObjCheck := false;
  27.     end
  28.     else
  29.       ObjCheck := true; end;
  30.  
  31. { This is pretty close to the same check that $R+ does. }
  32.